package com.imy.luasupport.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.imy.luasupport.core.LuaCore;

import java.util.List;

public class AppUtils {



  public static List<PackageInfo> getSystemInstallPackage() {
    PackageManager packageManager = LuaCore.get().getContext().getPackageManager();
    return packageManager.getInstalledPackages(0);
  }

  public static PackageInfo isSystemInstallPackage( String packageName) {
    List<PackageInfo> systemInstallPackage = getSystemInstallPackage();
    for (int i = 0; i < systemInstallPackage.size(); i++) {
      String packageName1 = systemInstallPackage.get(i).packageName;
      if (packageName1.equals(packageName)) {
        return systemInstallPackage.get(i);
      }
    }
    return null;
  }

  public static String getPackageNameByName(String checkjstring) {
    List<PackageInfo> systemInstallPackage = getSystemInstallPackage();
    for (int i = 0; i < systemInstallPackage.size(); i++) {
      ApplicationInfo applicationInfo = systemInstallPackage.get(i).applicationInfo;
      String charSequence = (String) applicationInfo.loadLabel(LuaCore.get().getContext()
      .getPackageManager()).toString();
      if (charSequence.equals(checkjstring)){
        return systemInstallPackage.get(i).packageName;
      }
    }
    return "";
  }
}
